package 高频题;

import 树.BST.ListNode;

public class 删除排序链表中的重复元素_83 {

    class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return null;
        }

        ListNode slow = head;
        ListNode fast = head.next;

        while (fast != null) {
            if (fast.val != slow.val) {
                //nums[slow]=nums[fast]
                slow.next = fast;
                //slow++
                slow = slow.next;
            }
            //fast++
            fast = fast.next;
        }
        //断开与后面重复元素的连接
        slow.next = null;
        return head;

    }
}
